<template>
    <Button type="primary" :loading='loadingState' :html-type='pType' @click="submitChange"><slot></slot></Button>
</template>
<script>
    export default{
        name:'btnSubmit',
        props:{
            pClick:{
                type:Function,
                required:true
            },
            pType:{
                type:String,
                default:'button'
            },
        },
        data(){
            return{
                loadingState:false,
            }
        },
        methods:{
          async submitChange(){
                this.$set(this,'loadingState',true);
                try{
                    const state = await this.pClick();
                    this.$set(this,'loadingState',false);
                }catch (e){
                    this.$set(this,'loadingState',false);
                }
          },
          handleCloneLoading(){
                this.$set(this,'loadingState',false);
          }
        },
        beforeDestroy(){
            this.$set(this,'loadingState',false);
        },
        components:{
        }
    }
</script>